package com.jcfk.eam.controller.main;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import com.jcfk.eam.domain.dto.main.EamInspectionTaskDTO;
import com.jcfk.eam.domain.query.main.EamInspectionTaskQuery;
import com.jcfk.eam.service.main.EamInspectionTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;


import com.jcfk.common.core.utils.ExcelUtils;
/**
 * 作业任务
 *
 * @author libinghai
 * @email 35738025@gqq.com
 * @date 2024-12-04
 */
@Api(tags = {"作业任务管理"})
@RestController
@RequestMapping("eamInspectionTask")
public class EamInspectionTaskController {
    @Autowired
    private EamInspectionTaskService eamInspectionTaskService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamInspectionTaskQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询作业任务")
    @PostMapping("/queryByPage")
    public RetPage<EamInspectionTaskDTO> queryByPage(@RequestBody ReqPageParam<EamInspectionTaskQuery> requestParam) {
        DataPage<EamInspectionTaskDTO> page = new DataPage<EamInspectionTaskDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            EamInspectionTaskDTO.class);
        page = eamInspectionTaskService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  作业任务
     * 根据id 查询详情
     */
    @ApiOperation("查询作业任务")
    @GetMapping("/get/{id}")
    public RetResult<EamInspectionTaskDTO> get(@PathVariable("id") String id) {
            EamInspectionTaskDTO item = eamInspectionTaskService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理作业任务
     */
    @ApiOperation("保存作业任务")
    @PostMapping("/save")
    @RequestLogHeader(modular = "作业任务管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamInspectionTaskDTO eamInspectionTask) {
        // 数据校验
        RetResult ret = eamInspectionTaskService.isValid(eamInspectionTask);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamInspectionTask.getId())){
            // 新增
            eamInspectionTaskService.insert(eamInspectionTask);
        } else{
            // 更新
            eamInspectionTaskService.update(eamInspectionTask);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除作业任务
     */
    @ApiOperation("批量删除作业任务")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "作业任务管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamInspectionTaskDTO eamInspectionTask) {
        return RetResult.ok(eamInspectionTaskService.removeBigBatch(eamInspectionTask.getIds()));
    }


    /**
     *  删除作业任务
     */
    @ApiOperation("删除作业任务")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "作业任务管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamInspectionTaskService.deleteItem(id);
        return RetResult.ok();
    }
}
